package com.stgy.lease.web.admin.controller.agreement;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stgy.lease.common.result.Result;
import com.stgy.lease.model.domain.LeaseAgreement;
import com.stgy.lease.web.admin.dto.AgreementInfoSearchDto;
import com.stgy.lease.web.admin.service.LeaseAgreementService;
import com.stgy.lease.web.admin.vo.AgreementDetailsVo;
import com.stgy.lease.web.admin.vo.AgreementInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:AgreementController
 * Package:com.stgy.lease.web.admin.controller
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/3 - 9:30
 */
@RestController
@RequestMapping("/admin/agreement")
@Tag(name = "租房管理模块")
public class AgreementController {
    @Autowired
    private LeaseAgreementService leaseAgreementService;

    //http://localhost:5174/admin/agreement/page?current=1&size=10&
    // provinceId=44&cityId=4403&districtId=440306&
    // apartmentId=1830404678916026369&roomNumber=101&
    // name=%E5%BC%A0%E4%B8%89&phone=157 GET
    @Operation(summary = "条件分页查询租约列表")
    @GetMapping("/page")
    public Result<Page<AgreementInfoVo>> page(AgreementInfoSearchDto searchDto) {
        return Result.ok(leaseAgreementService.pageItem(searchDto));
    }

    //http://localhost:5174/admin/agreement/saveOrUpdate POST
    //lease_agreement表
    @Operation(summary = "新增或更新租约信息")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement) {
        //业务判断：指定房间是否已存在租约，否则不能租
        return Result.build(leaseAgreementService.saveOrUpdateAgreement(leaseAgreement));
    }

    @Operation(summary = "根据id查询租约详情")
    @GetMapping("")
    public Result<AgreementDetailsVo> getDetailsById(@RequestParam Long id) {
        return Result.ok(leaseAgreementService.getDetailsById(id));
    }
    //http://localhost:5174/admin/agreement/removeById?id=1 DELETE
    @Operation(summary = "根据id删除租约信息")
    @DeleteMapping("/removeById")
    public Result<String> removeById(@RequestParam Long id) {
        return Result.build(leaseAgreementService.removeById(id));
    }


    //http://localhost:5174/admin/agreement/updateStatusById?
    // id=1830807527021879298&status=3 POST
    @Operation(summary = "根据id修改租约状态")
    @PostMapping("/updateStatusById")
    public Result<String> updateStatusById(@RequestParam Long id,@RequestParam Integer status) {
        return Result.build(leaseAgreementService.updateStatusById(id,status));
    }


}
